package com.sqx.modules.trends.controller;

import com.sqx.common.annotation.SysLog;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.trends.entity.Trends;
import com.sqx.modules.trends.entity.TrendsType;
import com.sqx.modules.trends.service.ITrendsService;
import com.sqx.modules.trends.vo.TrendsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户动态-管理端
 *
 * @author wuChang
 * @since 2023-09-26
 */
@RestController
@Api(value = "用户动态-管理端", tags = {"用户动态-管理端"})
@RequestMapping("/admin/trends/")
public class AdminTrendsController {
    @Autowired
    private ITrendsService iTrendsService;

    /**
     * 新增或修改用户动态
     *
     * @param trends
     * @return
     */
    @SysLog(value = "新增或修改用户动态", type = "1")
    @ApiOperation("新增或修改用户动态")
    @PostMapping(value = "saveTrends")
    public Result saveTrends(@ApiParam("动态实体") Trends trends) {
        trends.setStatus(1);
        return iTrendsService.saveTrends(trends);
    }

    /**
     * 审核动态发布
     *
     * @param status       状态 0待审核 1审核通过 2审核不通过
     * @param trendsId     动态id
     * @param auditContent 审核备注
     * @return
     */
    @ApiOperation("审核动态发布")
    @SysLog(value = "审核动态发布", type = "1")
    @PostMapping(value = "examineTrends")
    public Result examineTrends(@ApiParam("状态 0待审核 1审核通过 2审核不通过") Integer status,
                                @ApiParam("动态id") Long trendsId,
                                @ApiParam("审核备注") String auditContent) {
        return iTrendsService.examineTrends(status, trendsId, auditContent);
    }

    /**
     * 获取用户动态列表
     *
     * @param page  第几页
     * @param limit 多少条
     * @return
     */
    @ApiOperation("获取用户动态列表")
    @GetMapping(value = "getTrendsList")
    public Result getTrendsList(@ApiParam("页码") Integer page,
                                @ApiParam("条数") Integer limit,
                                @ApiParam("动态实体") TrendsVo trendsVo) {
        return iTrendsService.getTrendsListByAdmin(page, limit, null, trendsVo);
    }

    /**
     * 删除用户动态
     *
     * @param trendsId 动态id
     * @return
     */
    @ApiOperation("删除用户动态")
    @SysLog(value = "删除用户动态", type = "1")
    @GetMapping(value = "deleteTrends")
    public Result deleteTrends(@ApiParam("动态id") Long trendsId) {
        return iTrendsService.deleteTrendsById(trendsId);
    }

    @ApiOperation("添加或修改动态类型")
    @SysLog(value = "添加或修改动态类型", type = "1")
    @PostMapping(value = "addTrendsType")
    public Result addTrendsType(@ApiParam("动态类型实体") TrendsType trendsType) {
        return iTrendsService.addTrendsType(trendsType);
    }

    @ApiOperation("删除动态类型")
    @SysLog(value = "删除动态类型", type = "1")
    @GetMapping(value = "deleteTrendsType")
    public Result deleteTrendsType(@ApiParam("动态id") Long id) {
        return iTrendsService.deleteTrendsType(id);
    }

    @ApiOperation("查询动态类型列表")
    @GetMapping(value = "selectTrendsTypeList")
    public Result selectTrendsTypeList(@ApiParam("页码") Integer page,
                                       @ApiParam("条数") Integer limit,
                                       @ApiParam("动态类型实体") TrendsType trendsType) {
        return iTrendsService.selectTrendsTypeList(page, limit, trendsType);
    }

    @ApiOperation("查询动态类型详情")
    @GetMapping(value = "selectTrendsTypeDetail")
    public Result selectTrendsTypeDetail(@ApiParam("动态id") Long id) {
        return iTrendsService.selectTrendsTypeDetail(id);
    }

    /**
     * 管理端获取我的动态列表
     *
     * @param page     第几页
     * @param limit    多少条
     * @param trendsVo
     * @return
     */
    @ApiOperation("管理端获取我的动态列表")
    @GetMapping(value = "getMyTrendsList")
    public Result getMyTrendsList(@ApiParam("用户id") Long userId,
                                  @ApiParam("页码") Integer page,
                                  @ApiParam("条数") Integer limit,
                                  @ApiParam("被查看的用户id") Long byUserId,
                                  @ApiParam("用户动态实体") TrendsVo trendsVo) {
        trendsVo.setUserId(userId);
        return iTrendsService.getTrendsListByAdmin(page, limit, byUserId, trendsVo);
    }

    @ApiOperation("假删除动态类型")
    @SysLog(value = "假删除动态类型", type = "1")
    @GetMapping(value = "fakeDeletionTrends")
    public Result fakeDeletionTrends(@ApiParam("动态id") Long trendsId) {
        return iTrendsService.fakeDeletionTrends(trendsId);
    }

    @ApiOperation("修改动态虚拟点赞")
    @SysLog(value = "修改动态虚拟点赞", type = "1")
    @PostMapping(value = "updateTrendsLike")
    public Result updateTrendsLike(@ApiParam("动态id") Long trendsId,
                                   @ApiParam("要修改的虚拟点赞数量") Integer virtualLikeCount) {
        return iTrendsService.updateTrendsLike(trendsId, virtualLikeCount);
    }

    @ApiOperation("修改动态虚拟浏览量")
    @SysLog(value = "修改动态虚拟浏览量", type = "1")
    @PostMapping(value = "updateTrendsBrowse")
    public Result updateTrendsBrowse(@ApiParam("动态id") Long trendsId,
                                     @ApiParam("要修改的虚拟浏览数量") Integer virtualViewCount) {
        return iTrendsService.updateTrendsBrowse(trendsId, virtualViewCount);
    }

}
